//
//  AdoptHeaderView.m
//  PigMarket
//
//  Created by mac on 2019/3/28.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AdoptHeaderView.h"

@interface AdoptHeaderView ()<SDCycleScrollViewDelegate>

/**
 轮播图数组
 */
@property (nonatomic , strong) NSMutableArray *imageURLArr;
/**
 banner
 */
@property (nonatomic , strong) UIView *messageView;
/**
 消息
 */
@property (nonatomic , strong) UIImageView *messageIcon;
@end

@implementation AdoptHeaderView

#pragma mark - init method
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.cycleView];
    [self addSubview:self.messageView];
    [self.messageView addSubview:self.messageIcon];
    [self.messageView addSubview:self.couponTipsLab];
}

- (void)initLayout {
    // 布局子控件

    [self.cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(ScaleHeight(200));
        make.left.right.mas_equalTo(0);
    }];
    [self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.cycleView.mas_bottom);
        make.height.mas_equalTo(35);
    }];
    [self.messageIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.messageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    [self.couponTipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.messageView.mas_centerY);
        make.left.mas_equalTo(self.messageIcon.mas_right).offset(5);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(18);
    }];
}

#pragma mark - getter and setter

- (void)setCouponsStr:(NSString *)couponsStr {
    _couponsStr = couponsStr;
//    self.couponTipsLab.text = couponsStr;
}
- (SDCycleScrollView *)cycleView {
    if (!_cycleView) {
        _cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil];
        _cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _cycleView.currentPageDotColor = [UIColor primaryColor];
        _cycleView.autoScrollTimeInterval = 2.0;
        _cycleView.placeholderImage = [UIImage imageNamed:@"placeholder_large"];
    }
    return _cycleView;
}
- (UIView *)messageView {
    if (!_messageView) {
        _messageView = [[UIView alloc] init];
        _messageView.backgroundColor = [UIColor whiteColor];
    }
    return _messageView;
}
- (UIImageView *)messageIcon {
    if (!_messageIcon) {
        _messageIcon  = [[UIImageView alloc] init];
        _messageIcon.image = [UIImage imageNamed:@"adopt_message"];
    }
    return _messageIcon;
}
- (YYLabel *)couponTipsLab {
    if (!_couponTipsLab) {
        _couponTipsLab = [[YYLabel alloc] init];
        _couponTipsLab.textColor = [UIColor colorWithHexString:@"#687077"];
        _couponTipsLab.font = [UIFont systemFontOfSize:13];
        _couponTipsLab.text = @"您已拥有2张共计60元豚券，点击领养后再得50元豚券";
//        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:nil];
//
//        NSString *redStr = @"2";
//        NSRange range = [self.couponTipsLab.text rangeOfString:redStr];
//
//        if (range.location != NSNotFound) {
//             NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_couponTipsLab.text];
//            attributedString.yy_lineSpacing = 6;
//
//            @weakify(self)
//            [attributedString yy_setTextHighlightRange:range color:[UIColor colorWithHexString:@"EC8C00"] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
//                @strongify(self)
//
//            }];
//            _couponTipsLab.attributedText = attributedString;
//
//        }
        
    }
    return _couponTipsLab;
}
- (UIButton *)adoptNoticeBtn {
    if (!_adoptNoticeBtn) {
        _adoptNoticeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_adoptNoticeBtn setTitle:@"领养须知" forState:UIControlStateNormal];
        [_adoptNoticeBtn setTitleColor:[UIColor primaryColor] forState:UIControlStateNormal];
        _adoptNoticeBtn.titleLabel.font = [UIFont smallFont];
        _adoptNoticeBtn.layer.cornerRadius = 4;
        _adoptNoticeBtn.layer.masksToBounds = YES;
        _adoptNoticeBtn.layer.borderWidth = 1;
        _adoptNoticeBtn.layer.borderColor = [UIColor primaryColor].CGColor;
     
    }
    return _adoptNoticeBtn;
}

- (NSMutableArray *)imageURLArr {
    if (!_imageURLArr) {
        _imageURLArr = [[NSMutableArray alloc] init];
    }
    return _imageURLArr;
}

@end
